﻿
@{

}
<div class="bjui-pageContent">
    <table class="table table-bordered" id="datagrid-WordType@(Request.QueryString["_"])" data-toggle="datagrid"></table>
</div>
<script type="text/javascript">
    var wordTypeGrid@(Request.QueryString["_"]) = $('#datagrid-WordType@(Request.QueryString["_"])');
    wordTypeGrid@(Request.QueryString["_"]).datagrid({
        height: '100%',
        width: '100%',
        showToolbar: true,
        //toolbarItem: 'refresh,add,edit,save,exportf,del',
        toolbarItem: 'refresh,add,edit,save',
        dataUrl: '/WordType/WordTypeSearch',
        dataType: 'json',
        //editMode: { dialog: { width: 800, height: 250, mask: true, faicon: 'caret-right', icon: 'plus', title: "编辑", fresh: true } },
        editMode: "inline",
        editUrl: '/WordType/WordTypeUpsert',
        afterSave: saveCallBack@(Request.QueryString["_"]),
        @*delUrl: '/WordType/DelWordType',
        delPK: 'id',
        delConfirm : '@Html.CurLang("对该类型以及该类型下的数据将要被删除，确定继续吗？")',
        beforeDelete: delConfirm,*@
        paging: { pageSize: 20, orders: 'ADDED desc' },
        inlineEditMult: false,
        filterThead: true,
        linenumberAll: true,
        fieldSortable: true,
        columnFilter: true,
        showCheckboxcol: false,
        toolbarCustom: customtBtn@(Request.QueryString["_"]),
        exportOption: { type: "file", options: { url: "/WordType/WordTypeExport", outPutFileName: '语言' } },
        columns: [
            { name: 'id', align: 'center', width: 100, label: '@Html.CurLang("ID")', finalwidth: true, hide: true },
            { name: 'zh', align: 'center', width: 300, label: '简体中文' },
            { name: 'en', align: 'center', width: 300, label: 'English' },
            //{ name: 'jp', align: 'center', width: 250, label: '日本語' },
            //{ name: 'kor', align: 'center', width: 250, label: '한국어' },
            { name: 'spa', align: 'center', width: 300, label: 'Español' },
            { name: 'added', align: 'center', width: 250, label: '@Html.CurLang("添加时间")', type: 'date', pattern: 'yyyy-MM-dd HH:mm:ss', add: false, edit: false },
            { name: '', align: 'center', width: 300, label: '@Html.CurLang("操作")', menu: false, render: function (value, data) { return view_word_Detail(value, data) } }
        ]
    });

    function delConfirm@(Request.QueryString["_"])() {
        var datas = wordTypeGrid@(Request.QueryString["_"]).data("selectedDatas");
        if (!datas) {
            BJUI.alertmsg("info", '@Html.CurLang("未选中任何行！")');
            return;
        }

         BJUI.alertmsg('confirm', '@Html.CurLang("对该类型删除，将会同时删除该类型下的数据，确定删除吗？")', {
             okName: '@Html.CurLang("是")', cancelName: '@Html.CurLang("否")', okCall: function () {
                 BJUI.alertmsg('confirm', '@Html.CurLang("对该类型以及该类型下的数据将要被删除，确定继续吗？")', {
                     okName: '@Html.CurLang("是")', cancelName: '@Html.CurLang("否")', okCall: function () {
                         var id = wordTypeGrid@(Request.QueryString["_"]).datagrid("selectedDatas");
                        $.ajax({
                        url: "/WordType/DelWordType",
                        type: "POST",
                        data: { "id": datas[0].id },
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function (res) {
                            if (res.Code === 1) {
                                BJUI.alertmsg("ok", '@Html.CurLang("删除成功！")', { alertTimeout: 2000 });
                                setTimeout(refreshGri@(Request.QueryString["_"]), 2000);
                            } else {
                                BJUI.alertmsg('error', res.Msg);
                            }
                        },
                        error: function (xhr, status, errorThrown) {
                            BJUI.alertmsg('error', xhr.statusText);
                        }

                    });
                 }
                })
             }
            });
    }

    function fanyin@(Request.QueryString["_"])() {
        BJUI.alertmsg('confirm', '@Html.CurLang("已经翻译的是否需要替换？")', {
            okName: '@Html.CurLang("是")', cancelName: '@Html.CurLang("否")', okCall: function () {
                fanyinReq@(Request.QueryString["_"])(true);
            }, cancelCall: function () {
                fanyinReq@(Request.QueryString["_"])(false);
            }
        });
    }

    function fanyinReq@(Request.QueryString["_"])(isOK) {
        $.ajax({
            url: "/Lang/FanYin",
            type: "POST",
            data: { "type": "wordtype", "isReplace": isOK },
            dataType: "json",
            async: true,
            cache: false,
            success: function (res) {
                if (res.Code === 1) {
                    BJUI.alertmsg("ok", '@Html.CurLang("文本内容已翻译完成！")', { alertTimeout: 2000 });
                    setTimeout(refreshGri@(Request.QueryString["_"]), 2000);
                } else {
                    BJUI.alertmsg('error', res.Msg);
                }
            },
            error: function (xhr, status, errorThrown) {
                BJUI.alertmsg('error', xhr.statusText);
            }

        });
    }

    function refreshGri@(Request.QueryString["_"])() {
        wordTypeGrid@(Request.QueryString["_"]).datagrid('filter', {});
        //wordTypeGrid@(Request.QueryString["_"]).datagrid('filter', { "clearOldPostData": true });
    }
    function customtBtn@(Request.QueryString["_"])() {
        return $("<button type='button' class='btn btn-red' onclick='delConfirm@(Request.QueryString["_"])()'>" + '@Html.CurLang("删除")' + "</button> <button type='button' class='btn-default btn' onclick='fanyin@(Request.QueryString["_"])()'>" + '@Html.CurLang("实时翻译")' + "</button> <button type='button' class='btn-default btn' onclick='refreshGri@(Request.QueryString["_"])()'>@Html.CurLang("清空查询")</button>");
    }

    function saveCallBack@(Request.QueryString["_"])($trs, datas) {
        wordTypeGrid@(Request.QueryString["_"]).datagrid('refresh', false);
    }

    function view_word_Detail(val, data) {
        var txt = data.@ESMAM.Tools.CookieHelper.GetCookieValue(ESMAM.Web.Core.BaseController.CONST_COOKIE_LANG);
        return "<a href='#' data-toggle=\"navtab\" data-options=\"{id:'" + "view_word', url:'/Word/Index?typeid=" + data.id + "', title:'@Html.CurLang("受控词管理")-" + txt + "'}\">" + '@Html.CurLang("详细")' + "</a>";
    }

</script>
